package com.example.mountainwalker.mapper;

import com.example.mountainwalker.entity.HotelInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface HotelMapper {
    @Select("SELECT * FROM mw.hotel WHERE HotelName LIKE CONCAT('%', #{name}, '%')")
    List<HotelInfo> searchHotelsByName(@Param("name") String name);

    @Select("SELECT * FROM mw.hotel WHERE RegionID = #{regionId}")
    List<HotelInfo> searchHotelsByRegion(@Param("regionId") int regionId);

    @Select("SELECT * FROM mw.hotel WHERE ScenicSpotID = #{scenicSpotId}")
    List<HotelInfo> searchHotelsByScenicSpot(@Param("scenicSpotId") int scenicSpotId);

    @Select("SELECT * FROM mw.hotel")
    List<HotelInfo> getAllHotel();

    @Insert("INSERT INTO mw.hotel(HotelID,HotelName, RegionID, HotelAddress, MinimumPrice, ScenicSpotID, HotelLinks, UpdateTime) " +
            "VALUES(#{hotelID},#{hotelName}, #{regionID}, #{hotelAddress}, #{minimumPrice}, #{scenicSpotID}, #{hotelLinks}, #{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "hotelID")
    int insertHotel(HotelInfo hotelInfo);

    @Update("UPDATE mw.hotel SET HotelName=#{hotelName}, RegionID=#{regionID}, HotelAddress=#{hotelAddress}, " +
            "MinimumPrice=#{minimumPrice}, ScenicSpotID=#{scenicSpotID}, HotelLinks=#{hotelLinks}, UpdateTime=#{updateTime} " +
            "WHERE HotelID=#{hotelID}")
    int updateHotel(HotelInfo hotelInfo);

    @Delete("DELETE FROM mw.hotel WHERE HotelID=#{hotelId}")
    int deleteHotel(@Param("hotelId") int hotelId);

    @Delete("DELETE FROM mw.hotel WHERE RegionID = #{regionId}")
    int deleteHotelsByRegionId(@Param("regionId") Integer regionId);
}